package net.interneteidee.converter;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import net.interneteidee.entity.Categoria;

@ManagedBean
@SessionScoped
public class CategoriaConverter extends GenericConverter {

	 	@Override
	    public Object getAsObject(FacesContext facescontext, UIComponent uicomponent, String value) {
	        if (value == null) return null;
	       
	       String [] ris = value.split("-");
	       int idCategoria = Integer.parseInt(ris[0]);
	       
	       return prodottoCategoriaFamigliaService.findCategoriaById(idCategoria);
	
	       
	    }

	    @Override
	    public String getAsString(FacesContext facescontext, UIComponent uicomponent, Object obj) {
	        if (obj == null) return null;
	  //      System.out.println(((Categoria) obj).getIdCategoria()+"-"+((Categoria) obj).getNome());
	        return ((Categoria) obj).getIdCategoria()+"-"+((Categoria) obj).getNome();
		       
	    }
	
}
